//
//  UIButton+SRCustomFrame.m
//  UWOApp
//
//  Created by 索晓晓 on 2018/4/3.
//  Copyright © 2018年 SXiao.RR. All rights reserved.
//

char *kSRImageRectKey = "kSRImageRectKey";
char *kSRTitleRectKey = "kSRTitleRectKey";

#import "UIButton+SRCustomFrame.h"
#import <objc/runtime.h>

@implementation UIButton (SRCustomFrame)

- (CGRect)sr_imageRect
{
    id imageR  = objc_getAssociatedObject(self, kSRImageRectKey);
    
    if (imageR == nil || ![imageR isKindOfClass:[NSValue class]]) {
        imageR = [NSValue valueWithCGRect:CGRectZero];
    }
    
    return [imageR CGRectValue];
}
- (void)setSr_imageRect:(CGRect)sr_imageRect
{
    objc_setAssociatedObject(self, kSRImageRectKey, [NSValue valueWithCGRect:sr_imageRect], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (CGRect)sr_titleRect
{
    id titleR  = objc_getAssociatedObject(self, kSRTitleRectKey);
    
    if (titleR == nil) {
        titleR = [NSValue valueWithCGRect:CGRectZero];
    }
    
    return [titleR CGRectValue];
}
- (void)setSr_titleRect:(CGRect)sr_titleRect
{
    objc_setAssociatedObject(self, kSRTitleRectKey, [NSValue valueWithCGRect:sr_titleRect], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
